// login.js
const db = wx.cloud.database();
const users = db.collection('users');

Page({
    onSubmit(event) {
        const { sno, password } = event.detail.value;
        users.where({ sno, password }).get().then(res => {
            if (res.data.length > 0) {
                wx.setStorageSync('user', res.data[0]);
                wx.showToast({
                    title: '登录成功',
                    icon: 'success'
                });
                wx.redirectTo({
                    url: '/pages/profile/profile'
                });
            } else {
                wx.showToast({
                    title: '用户名或密码错误',
                    icon: 'error'
                });
            }
        });
    }
});